﻿
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Sharp.Domain.PlatformBoundedContext.PersonModule.Aggregates;

namespace Sharp.Domain.PlatformBoundedContext.ModelConfigurations
{
    public partial class GroupConfiguration
        : EntityTypeConfiguration<Group>
    {
        public GroupConfiguration()
        {
            // keys
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Id)
                .IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            Property(t => t.Code)
                .HasMaxLength(50)
                .IsOptional();

            Property(t => t.Title)
                .HasMaxLength(50)
                .IsOptional();
            Property(t => t.Remark)
                .HasMaxLength(255)
                .IsOptional();

            Property(t => t.CheckInTime)
                .IsRequired();
            Property(t => t.CheckInUserId)
                .IsRequired();
            Property(t => t.ModifiTime)
                .IsOptional();
            Property(t => t.ModifiedUserId)
                .IsOptional();

            HasOptional(t => t.Org)
                .WithMany(t => t.Groups)
                .HasForeignKey(d => d.OrgId);

            HasMany(t => t.Orgs)
                .WithMany(t => t.Groups1)
                .Map(m =>
                {
                    m.ToTable("Platform_OrgsGroups", "dbo");
                    m.MapLeftKey("OrgId");
                    m.MapRightKey("GroupId");
                });


        }
    }
}